﻿using ConfExpert.Forms.Base;
using DevExpress.Utils;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevTeam;
using System;
using System.Data;
using System.Drawing;

namespace ConfExpert.Forms.ImportWizards.GomlekCekiListesi
{
    public partial class BDMatch : XForm
    {
        int DagilimId;
        public DataTable dt;
        public BDMatch(DataTable dt, int DagilimId)
        {
            InitializeComponent();
            this.DagilimId = DagilimId;
            this.dt = dt;
        }

        private void BDMatch_Load(object sender, EventArgs e)
        {
            d = ExecuteDataSet("GetBDMatch", dt.Serialize(), DagilimId, WhoAmI);
            gridView1.Init(d.Tables[0]);

            gridView1.Columns["Beden"].ColumnEdit = GetCustomGLE(gridView1.Dataset().Tables[1], "Beden", "Beden");
            ((RepositoryItemGridLookUpEdit)gridView1.Columns["Beden"].ColumnEdit).TextEditStyle = TextEditStyles.DisableTextEditor;
            
            gridView1.MakeColumnInvisible("Name");
            gridView1.RowCellStyle += gridView1_RowCellStyle;
            btnKaydet.ItemClick += btnKaydet_ItemClick;
            gridView1.BestFitColumns();
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if(e.Column.FieldName == "Caption")
                e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
        }

        DataSet d;
            void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEditing();
            dt = ExecuteDataTable("GetBDMatch", gridView1.Serialize(), DagilimId, WhoAmI);
            dt.TableName = "BD";
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
    }
}
